import 'package:gold/generated/json/base/json_convert_content.dart';
import 'package:gold/model/coupon_model.dart';

CouponModel $CouponModelFromJson(Map<String, dynamic> json) {
  final CouponModel couponModel = CouponModel();
  final int? userCouponId = jsonConvert.convert<int>(json['user_coupon_id']);
  if (userCouponId != null) {
    couponModel.userCouponId = userCouponId;
  }
  final String? receivedAt = jsonConvert.convert<String>(json['received_at']);
  if (receivedAt != null) {
    couponModel.receivedAt = receivedAt;
  }
  final String? expiredAt = jsonConvert.convert<String>(json['expired_at']);
  if (expiredAt != null) {
    couponModel.expiredAt = expiredAt;
  }
  final String? couponName = jsonConvert.convert<String>(json['coupon_name']);
  if (couponName != null) {
    couponModel.couponName = couponName;
  }
  final double? minAmount = jsonConvert.convert<double>(json['min_amount']);
  if (minAmount != null) {
    couponModel.minAmount = minAmount;
  }
  final double? discountAmount = jsonConvert.convert<double>(json['discount_amount']);
  if (discountAmount != null) {
    couponModel.discountAmount = discountAmount;
  }
  return couponModel;
}

Map<String, dynamic> $CouponModelToJson(CouponModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['user_coupon_id'] = entity.userCouponId;
  data['received_at'] = entity.receivedAt;
  data['expired_at'] = entity.expiredAt;
  data['coupon_name'] = entity.couponName;
  data['min_amount'] = entity.minAmount;
  data['discount_amount'] = entity.discountAmount;
  return data;
}

extension CouponModelExtension on CouponModel {
  CouponModel copyWith({
    int? userCouponId,
    String? receivedAt,
    String? expiredAt,
    String? couponName,
    double? minAmount,
    double? discountAmount,
  }) {
    return CouponModel()
      ..userCouponId = userCouponId ?? this.userCouponId
      ..receivedAt = receivedAt ?? this.receivedAt
      ..expiredAt = expiredAt ?? this.expiredAt
      ..couponName = couponName ?? this.couponName
      ..minAmount = minAmount ?? this.minAmount
      ..discountAmount = discountAmount ?? this.discountAmount;
  }
}